package com.cici.controller;


import com.cici.body.UserCreateBody;
import com.cici.entity.User;
import com.cici.exception.ExceptionEnumImpl;
import com.cici.exception.common.RestNotFoundException;
import com.cici.mapper.UserMapper;
import com.cici.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Optional;

import static org.springframework.http.HttpStatus.OK;

@RestController
@RequestMapping("/mybatisplus")
public class TestMain {

//    @Autowired
////    private UserMapper studentMapper;

    @Autowired
    private IUserService userService;


//    @ApiOperation(value = "充值表请求体", notes = "充值咋豆流水记录", httpMethod = "POST")
    @RequestMapping(method = RequestMethod.POST)
    @ResponseStatus(HttpStatus.OK)
    public ResponseEntity<User> createUserPeasRecord(@RequestBody UserCreateBody body) {
        return Optional.ofNullable(userService.create(body))
                .map(s->new ResponseEntity<>(s,OK))
                .orElseThrow(()->new RestNotFoundException(ExceptionEnumImpl.REQUEST_BODY_IS_NULL,
                        "Create UserPeasRecord is fail ."));
    }





//    @GetMapping("/list")
//    public List<User> list(){
//        List<User> students = studentMapper.selectList(null);
//        return students;
//    }
//
//    @GetMapping("/save")
//    public String save(){
//        User student = new User();
//        student.setId(2);
//        student.setCity("杭州");
//        student.setName("马云");
//        student.setSchool("杭州师范");
//        studentMapper.insert(student);
//        return "success";
//
//    }



}
